package com.projectsquirrel;


import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Color;

import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TableLayout;
import android.widget.TextView;
import android.widget.ToggleButton;

public class mainMenu1 extends Activity {
	private ToggleButton onEmulator;
	private static final int VIEW_PICTURE = 2;

	@Override
	/*
	 * This is the main menu of the application and it will have:
	 * new Observation button
	 * saved observations button
	 * settings icon
	 * info icon
	 * 
	 */
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.homescreen);
	    ImageButton newObsButton = (ImageButton) findViewById(R.id.newObservationButton);
	    ImageButton savedObsButton = (ImageButton) findViewById(R.id.savedObservationsButton);
	    ImageButton addPhotoButton = (ImageButton) findViewById(R.id.addPhotoButton);
	    ImageButton addStoryButton = (ImageButton) findViewById(R.id.addStoryButton);
	   // ImageButton sharedStoriesButton = (ImageButton) findViewById(R.id.sharedStoriesButton);
	    //onEmulator = (ToggleButton) findViewById(R.id.onEmulatorToggle);
	    ImageButton settingsIconButton = (ImageButton) findViewById(R.id.settingnfoScreenIcon);
	    ImageButton infoIconButton = (ImageButton) findViewById(R.id.infoScreenIcon);
	    final SharedPreferences pref = getSharedPreferences("AppSettings",MODE_PRIVATE);
	    
	    
	    newObsButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				// TODO Auto-generated method stub
				//Intent i = new Intent(mainMenu1.this, newObservation.class);
				Intent i = new Intent(mainMenu1.this, NewObservation2.class);
				//i.putExtra("OnEmulator", onEmulator.isChecked());
				SharedPreferences.Editor editor = pref.edit();  
				Observation.resetInstance();
				  //editor.putBoolean("ON_EMULATOR", onEmulator.isChecked());
				  editor.commit();
		        startActivity(i);
			}	    	
	    });
	    settingsIconButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent i = new Intent(mainMenu1.this, settingsMenu.class);
		        startActivity(i);
			}	    	
	    });
	    infoIconButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent i = new Intent(mainMenu1.this, infoMenu.class);
		        startActivity(i);
			}	    	
	    });
	    savedObsButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent i = new Intent(mainMenu1.this, savedObservations.class);
		        startActivity(i);
			}	    	
	    });
	    
	    
	    addStoryButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent i = new Intent(mainMenu1.this, StoryUpload.class);
		        startActivity(i);
			}	    	
	    });
	    
	    addPhotoButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent i = new Intent(mainMenu1.this, photoUpload.class);
				//i.putExtra("OnEmulator", onEmulator.isChecked());
		        startActivity(i);
			}	    	
	    });
	    
	     /*sharedStoriesButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent i = new Intent(mainMenu1.this, savedStories.class);
				//i.putExtra("OnEmulator", onEmulator.isChecked());
		        startActivity(i);
			}	    	
	    });*/
	    
	    
	    
	}

	public String getPath(Uri uri) {
        String[] projection = { MediaStore.Images.Media.DATA };
        Cursor cursor = managedQuery(uri, projection, null, null, null);
        if(cursor!=null)
        {
            //HERE YOU WILL GET A NULLPOINTER IF CURSOR IS NULL
            //THIS CAN BE, IF YOU USED OI FILE MANAGER FOR PICKING THE MEDIA
            int column_index = cursor
            .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            return cursor.getString(column_index);
        }
        else return null;
    }
	
 	@Override
	protected void onStart(){
     	// for the dialog indicating the gps is disabled
		super.onStart();
 		/*
 		Calendar calendar = new GregorianCalendar();
 	    int hour = calendar.get(Calendar.HOUR); 		
 	    if(hour>18 || hour<10)
 		{
 			TableLayout l = (TableLayout) findViewById(R.id.homeScreen);
 			int color=Color.WHITE;
 			l.setBackgroundColor(color);
 			TextView t = (TextView) findViewById(R.id.textView1);
 			t.setText("Home Screen (Night Mode)");
 			
 		}
 		*/	
 		
	}

}
//*/